<?php
/**
 * Created by PhpStorm.
 * User: apple
 * Date: 2018/7/22
 * Time: 下午4:12
 */
namespace PddWechat\Models\Pos\Dao;
use Dai\Framework\Base\BaseDao;
use PddWechat\Models\Pos\DataObject\PostInvateDo;

/**
 * Class PostInvateDao
 * @dataObject(\PddWechat\Models\Pos\DataObject\PostInvateDo)
 * @package PddWechat\Models\Pos\Dao
 */
class PostInvateDao extends BaseDao
{
    /**
     * @param PostInvateDo $postInvateDo
     * @return PostInvateDo
     */
    public function insert(PostInvateDo $postInvateDo)
    {
        $postInvateDo->id = $this->execute("user.post_invate.insert", $postInvateDo);
        return $postInvateDo;
    }

    public function getApplyInfoByPhone($phone)
    {
        $param = [
            'phone' => $phone,
            'select' => '*',
        ];
        $res = $this->execute("user.post_invate.select_by_phone", $param);
        if( count($res) > 0 ) {
            /** @var PostInvateDo $ret */
            $ret = $this->trimBase($res[0]);
            return $ret;
        }
        return null;
    }

    public function getApplyInfoByOpenId($openid)
    {
        $param = [
            'recommendOpenId' => $openid,
            'select' => '*',
        ];
        $res = $this->execute("user.post_invate.select_by_recommendopenid", $param);
        if( count($res) > 0 ) {
            /** @var PostInvateDo $ret */
            $ret = $this->trimBase($res[0]);
            return $ret;
        }
        return null;
    }

    public function getApplyListByOpenId($openid)
    {
        $param = [
            'recommendOpenId' => $openid,
            'select' => '*',
        ];
        $res = $this->execute("user.post_invate.select_by_recommendopenid", $param);
        $output = [];
        if( count($res) > 0 ) {
            foreach ($res as $item) {
                $output[] = $this->trimBase($item);
            }
        }
        return $output;
    }

    public function getApplyInfoByOrderNum($orderNum) {
        $param = [
            'orderNum' => $orderNum,
            'select' => '*',
        ];
        $res = $this->execute("user.post_invate.select_by_ordernum",$param);
        if( count($res) > 0 ) {
            /** @var PostInvateDo $ret */
            $ret = $this->trimBase($res[0]);
            return $ret;
        }
        return null;
    }
}